/* eslint valid-jsdoc: "off" */

"use strict";

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
const path = require("path");

module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = {};

  config.cors = {
    origin: "http://127.0.0.1:8081", // 允许前端地址
    allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH",
  };
  // console.log('xx', appInfo.baseDir);
  config.static = {
    prefix: "/admin/public/", // URL 前缀
    dir: path.join(appInfo.baseDir, "app/public"), // 静态文件目录
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1699941406852_1525";

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  rootPathname: "/v1";

  // 数据库连接
  config.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: "127.0.0.1",
      // 端口号
      port: "3306",
      // 用户名
      user: "root",
      // 密码
      password: "123456",
      // password: "test1234",
      // 数据库名
      database: "counter",
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
  };

  config.security = {
    csrf: {
      enable: false,
    },
  };

  config.jwt = {
    // token 密码
    secret: "lijie", // 可以自定义秘钥
    // sign: { //jwt.sign(***,***,[options,***])方法中，options的默认设置可以在这里配置；
    //   // 过期时间8小时
    //   expiresIn: 8 * (60 * 60)
    // }
  };

  config.multipart = {
    fileSize: "100mb",
    mode: "file",
    whitelist: [".xlsx", ".docx", ".png", ".jpg"],
  };

  config.redis = {
    client: {
      port: 6379, // Redis port
      host: "127.0.0.1", // Redis host
      password: null,
      db: 0,
    },
  };

  return {
    ...config,
    ...userConfig,
  };
};
